Adds an element with the provided key and value to the
IDictionary.
Syntax
Parameters
- key
- The object to use as the key of the element to add.
- value
- The object to use as the value of the element to add.
Exceptions
Example
Library/Library.Test/TestBTreeDictionary.cs
C# | Copy Code |
---|
BTreeDictionary<int, string> data = new BTreeDictionary<int, string>(Comparer);
for (int i = 0; i < 100; i++)
Assert.IsTrue(data.TryAdd(i, i.ToString()));
Assert.AreEqual(50, new List<KeyValuePair<int, string>>(data.EnumerateFrom(50)).Count);
Assert.AreEqual(25, new List<KeyValuePair<int, string>>(data.EnumerateFrom(75)).Count);
for (int i = 0; i < 100; i++)
{
int first = -1;
foreach (KeyValuePair<int, string> kv in data.EnumerateFrom(i))
{
first = kv.Key;
break;
}
Assert.AreEqual(i, first);
} |
VB.NET | Copy Code |
---|
Dim data As New BTreeDictionary(Of Integer, String)(Comparer)
Dim i As Integer = 0
While i < 100
Assert.IsTrue(data.TryAdd(i, i.ToString()))
System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)
End While
Assert.AreEqual(50, New List(Of KeyValuePair(Of Integer, String))(data.EnumerateFrom(50)).Count)
Assert.AreEqual(25, New List(Of KeyValuePair(Of Integer, String))(data.EnumerateFrom(75)).Count)
Dim i As Integer = 0
While i < 100
Dim first As Integer = -1
For Each kv As KeyValuePair(Of Integer, String) In data.EnumerateFrom(i)
first = kv.Key
Exit For
Next
Assert.AreEqual(i, first)
System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)
End While |
Requirements
Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7
See Also